//
//  HCStatusRetweetView.swift
//  Hweibome
//
//  Created by 何川 on 15/12/10.
//  Copyright © 2015年 hechuan. All rights reserved.
//

import UIKit
import SnapKit

class HCStatusRetweetView: UIView {

    var bottomConstraint: Constraint?
    
    var statusViewModel: HCStatusViewModel?{
    didSet{
        contentLabel.text = statusViewModel?.retweetText
        
        self.bottomConstraint?.uninstall()
        if let pic_urls = statusViewModel?.status?.retweeted_status?.pic_urls where pic_urls.count>0
        {
            pictureView.pic_urls = pic_urls
            pictureView.hidden = false
            
            snp_updateConstraints(closure: { (make) -> Void in
                self.bottomConstraint = make.bottom.equalTo(pictureView).offset(HCStatusCellMargin).constraint
            })
        }
        else {
            pictureView.hidden = true
            snp_updateConstraints(closure: { (make) -> Void in
                self.bottomConstraint = make.bottom.equalTo(contentLabel).offset(HCStatusCellMargin).constraint
            })
        }
        }
        } 
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
//        backgroundColor = RandomColor()
//        contentLabel.text = "想浪微博新浪微博微博微薄围脖微波外部想浪微博新浪微博微博微薄围脖微波外部想浪微博新浪微博微博微薄围脖微波外部想浪微博新浪微博微博微薄围脖微波外部想浪微博新浪微博微博微薄围脖微波外部想浪微博新浪微博微博微薄围脖微波外部想浪微博新浪微博微博微薄围脖微波外部"
        backgroundColor = UIColor(white:0.95,alpha: 1)
        addSubview(contentLabel)
        addSubview(pictureView)
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(HCStatusCellMargin)
            make.top.equalTo(self).offset(HCStatusCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(HCStatusCellMargin)
         //   make.size.equalTo(CGSize(width: 100, height: 100))
        }
        self.snp_makeConstraints { (make) -> Void in
//            self.bottomConstraint = make.bottom.equalTo(pictureView).offset(HCStatusCellMargin).constraint
            self.bottomConstraint = make.bottom.equalTo(pictureView).offset(HCStatusCellMargin).constraint
        }
    }
    
    
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), fontSize: HCStatusContentFontSize,maxWidth: SCREENW - 2 * HCStatusCellMargin)
    
    private lazy var pictureView: HCStatusPictureView = {
        let view = HCStatusPictureView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
}

